package com.jrx.anytxn.transaction.job.autoPayment.step;

import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.entity.TlPaymentLog;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.batch.MyBatisPagingItemReader;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *  第三次批扣初始化读取上次批扣失败记录
 *
 * @Author yhy
 * @Date 2023/4/25 10:30
 *
 */
public class AutoPaymentThirdFailInitReader extends MyBatisPagingItemReader<TlPaymentLog> {

    /**
     * 获取上次批扣失败记录
     * @param businessDate 当前业务日期
     * @param sqlSessionFactory  sql工厂对象
     * @param pagesize 分页参数
     */
    public AutoPaymentThirdFailInitReader(Date businessDate, SqlSessionFactory sqlSessionFactory, Integer pagesize){
        setSaveState(false);
        setPageSize(pagesize);
        setSqlSessionFactory(sqlSessionFactory);
        setQueryId("com.jrx.anytxn.transaction.mapper.ext.ExtTlPaymentLogMapper.selectByDistinctForBatch");

        Map<String, Object> map = new HashMap<>();
        map.put("businessDate",businessDate);
        // 默认查询批扣交易记录
        map.put("paymentTypeList", Collections.singletonList(TransBizConstant.REPAYMENT_TYPE_AUTO));
        // 交易状态为失败
        map.put("sumStatus",TransBizConstant.PAYMENT_LOG_SUM_STATUS_F);
        setParameterValues(map);
    }
}
